<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Kafka Leader 宕机与 ISR 恢复策略</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            min-height: 100vh;
        }
        .hero-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        .card-hover {
            transition: all 0.3s ease;
        }
        .card-hover:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 40px rgba(0,0,0,0.1);
        }
        .text-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
        }
        .section-title::before {
            content: '';
            position: absolute;
            left: 0;
            bottom: -10px;
            width: 60px;
            height: 4px;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            border-radius: 2px;
        }
        .list-item::before {
            content: '';
            position: absolute;
            left: -25px;
            top: 12px;
            width: 8px;
            height: 8px;
            background: #667eea;
            border-radius: 50%;
        }
        .mermaid {
            display: flex;
            justify-content: center;
            margin: 2rem 0;
        }
        @keyframes fadeIn {
            from { opacity: 0; transform: translateY(20px); }
            to { opacity: 1; transform: translateY(0); }
        }
        .fade-in {
            animation: fadeIn 0.8s ease-out;
        }
    </style>
</head>
<body>
    <!-- Hero Section -->
    <div class="hero-gradient text-white py-20 px-6">
        <div class="max-w-6xl mx-auto text-center fade-in">
            <h1 class="text-5xl md:text-6xl font-bold mb-6">
                <i class="fas fa-server mr-4"></i>
                Kafka 故障恢复机制
            </h1>
            <p class="text-xl md:text-2xl opacity-90 max-w-3xl mx-auto">
                深入解析 Leader 宕机与 ISR 为空时的处理策略
            </p>
            <div class="mt-8 flex justify-center space-x-4">
                <span class="bg-white bg-opacity-20 px-4 py-2 rounded-full text-sm">
                    <i class="fas fa-exclamation-triangle mr-2"></i>高可用性
                </span>
                <span class="bg-white bg-opacity-20 px-4 py-2 rounded-full text-sm">
                    <i class="fas fa-sync-alt mr-2"></i>故障恢复
                </span>
                <span class="bg-white bg-opacity-20 px-4 py-2 rounded-full text-sm">
                    <i class="fas fa-shield-alt mr-2"></i>数据一致性
                </span>
            </div>
        </div>
    </div>

    <!-- Main Content -->
    <div class="max-w-6xl mx-auto px-6 py-12">
        <!-- Introduction -->
        <div class="bg-white rounded-2xl shadow-xl p-8 mb-8 card-hover">
            <div class="flex items-center mb-4">
                <i class="fas fa-info-circle text-3xl text-purple-600 mr-4"></i>
                <h2 class="text-2xl font-bold">核心问题概述</h2>
            </div>
            <p class="text-lg text-gray-700 leading-relaxed">
                当 Kafka 分区副本中的 Leader 宕机且 ISR（In-Sync Replicas）为空时，这种情况通常表明系统面临严重的可用性挑战。这不仅影响消息的正常处理，还可能导致数据丢失的风险。
            </p>
        </div>

        <!-- Visualization -->
        <div class="bg-white rounded-2xl shadow-xl p-8 mb-8">
            <h2 class="text-2xl font-bold mb-6 text-center">Kafka 故障处理流程图</h2>
            <div class="mermaid">
                graph TD
                    A[Leader 正常运行] -->|硬件/软件故障| B[Leader 宕机]
                    B --> C{检查 ISR 状态}
                    C -->|ISR 不为空| D[从 ISR 中选举新 Leader]
                    C -->|ISR 为空| E[紧急处理模式]
                    E --> F[尝试恢复副本同步]
                    E --> G[考虑数据丢失风险]
                    F --> H[重新选举 Leader]
                    G --> H
                    H --> I[恢复正常服务]
                    D --> I
                    
                    style A fill:#4ade80,stroke:#22c55e,stroke-width:2px
                    style B fill:#f87171,stroke:#ef4444,stroke-width:2px
                    style E fill:#fbbf24,stroke:#f59e0b,stroke-width:2px
                    style I fill:#60a5fa,stroke:#3b82f6,stroke-width:2px
            </div>
        </div>

        <!-- Section 1: Leader 宕机原因分析 -->
        <div class="grid md:grid-cols-2 gap-8 mb-12">
            <div class="bg-white rounded-2xl shadow-xl p-8 card-hover">
                <div class="flex items-center mb-6">
                    <div class="w-12 h-12 bg-red-100 rounded-full flex items-center justify-center mr-4">
                        <i class="fas fa-server text-red-600 text-xl"></i>
                    </div>
                    <h3 class="text-xl font-bold relative section-title">硬件故障</h3>
                </div>
                <ul class="space-y-4">
                    <li class="flex items-start">
                        <i class="fas fa-hdd text-red-500 mt-1 mr-3"></i>
                        <span class="text-gray-700">磁盘故障导致数据无法读写</span>
                    </li>
                    <li class="flex items-start">
                        <i class="fas fa-plug text-red-500 mt-1 mr-3"></i>
                        <span class="text-gray-700">服务器断电或电源故障</span>
                    </li>
                    <li class="flex items-start">
                        <i class="fas fa-network-wired text-red-500 mt-1 mr-3"></i>
                        <span class="text-gray-700">网络硬件故障导致节点失联</span>
                    </li>
                </ul>
            </div>

            <div class="bg-white rounded-2xl shadow-xl p-8 card-hover">
                <div class="flex items-center mb-6">
                    <div class="w-12 h-12 bg-orange-100 rounded-full flex items-center justify-center mr-4">
                        <i class="fas fa-bug text-orange-600 text-xl"></i>
                    </div>
                    <h3 class="text-xl font-bold relative section-title">软件问题</h3>
                </div>
                <ul class="space-y-4">
                    <li class="flex items-start">
                        <i class="fas fa-desktop text-orange-500 mt-1 mr-3"></i>
                        <span class="text-gray-700">操作系统崩溃或内核错误</span>
                    </li>
                    <li class="flex items-start">
                        <i class="fas fa-code text-orange-500 mt-1 mr-3"></i>
                        <span class="text-gray-700">Kafka 服务进程异常退出</span>
                    </li>
                    <li class="flex items-start">
                        <i class="fas fa-memory text-orange-500 mt-1 mr-3"></i>
                        <span class="text-gray-700">内存溢出或资源耗尽</span>
                    </li>
                </ul>
            </div>
        </div>

        <!-- Section 2: 处理方法 -->
        <div class="bg-gradient-to-r from-purple-50 to-pink-50 rounded-2xl p-8 mb-12">
            <h2 class="text-3xl font-bold mb-8 text-center text-gradient">
                <i class="fas fa-tools mr-3"></i>处理方法与恢复策略
            </h2>
            
            <div class="grid md:grid-cols-2 gap-6">
                <div class="bg-white rounded-xl p-6 card-hover">
                    <div class="flex items-center mb-4">
                        <div class="w-10 h-10 bg-blue-500 rounded-full flex items-center justify-center mr-3">
                            <i class="fas fa-search text-white"></i>
                        </div>
                        <h4 class="text-lg font-semibold">故障检测</h4>
                    </div>
                    <p class="text-gray-700">Kafka 会通过心跳机制检测到 Leader 宕机，并将其标记为不可用状态，触发故障恢复流程。</p>
                </div>

                <div class="bg-white rounded-xl p-6 card-hover">
                    <div class="flex items-center mb-4">
                        <div class="w-10 h-10 bg-green-500 rounded-full flex items-center justify-center mr-3">
                            <i class="fas fa-sync text-white"></i>
                        </div>
                        <h4 class="text-lg font-semibold">ISR 恢复策略</h4>
                    </div>
                    <p class="text-gray-700">当 ISR 为空时，表示没有副本与 Leader 同步，需要谨慎处理以避免数据丢失。</p>
                </div>

                <div class="bg-white rounded-xl p-6 card-hover">
                    <div class="flex items-center mb-4">
                        <div class="w-10 h-10 bg-purple-500 rounded-full flex items-center justify-center mr-3">
                            <i class="fas fa-crown text-white"></i>
                        </div>
                        <h4 class="text-lg font-semibold">重新分配 Leader</h4>
                    </div>
                    <p class="text-gray-700">系统会尝试选举新的 Leader，优先从 ISR 中选择，若 ISR 为空则需要特殊处理。</p>
                </div>

                <div class="bg-white rounded-xl p-6 card-hover">
                    <div class="flex items-center mb-4">
                        <div class="w-10 h-10 bg-yellow-500 rounded-full flex items-center justify-center mr-3">
                            <i class="fas fa-redo text-white"></i>
                        </div>
                        <h4 class="text-lg font-semibold">故障恢复策略</h4>
                    </div>
                    <p class="text-gray-700">通过动态选举和副本同步机制，恢复正常的消息处理流程，确保服务可用性。</p>
                </div>
            </div>
        </div>

        <!-- Section 3: 系统稳定性与监控 -->
        <div class="bg-white rounded-2xl shadow-xl p-8">
            <h2 class="text-3xl font-bold mb-8 text-center">
                <i class="fas fa-chart-line mr-3 text-purple-600"></i>
                系统稳定性与监控
            </h2>

            <div class="grid md:grid-cols-3 gap-6">
                <div class="text-center">
                    <div class="w-20 h-20 bg-gradient-to-br from-blue-400 to-blue-600 rounded-full flex items-center justify-center mx-auto mb-4">
                        <i class="fas fa-bell text-white text-2xl"></i>
                    </div>
                    <h4 class="text-lg font-semibold mb-2">监控和报警</h4>
                    <p class="text-gray-600 text-sm">建立完善的监控体系，实时追踪 Leader 状态和 ISR 变化，及时发现异常。</p>
                </div>

                <div class="text-center">
                    <div class="w-20 h-20 bg-gradient-to-br from-green-400 to-green-600 rounded-full flex items-center justify-center mx-auto mb-4">
                        <i class="fas fa-database text-white text-2xl"></i>
                    </div>
                    <h4 class="text-lg font-semibold mb-2">数据一致性保证</h4>
                    <p class="text-gray-600 text-sm">通过 ISR 机制确保数据副本的一致性，防止数据丢失和不一致问题。</p>
                </div>

                <div class="text-center">
                    <div class="w-20 h-20 bg-gradient-to-br from-purple-400 to-purple-600 rounded-full flex items-center justify-center mx-auto mb-4">
                        <i class="fas fa-shield-alt text-white text-2xl"></i>
                    </div>
                    <h4 class="text-lg font-sem